package org.indp.mongowl.ui;

import com.mongodb.DBCollection;
import com.vaadin.ui.Component;
import com.vaadin.ui.Table;
import com.vaadin.ui.VerticalLayout;
import org.indp.mongowl.services.ServerConnection;

/**
 *
 */
public class CollectionBrowserComponent extends VerticalLayout {

    private final ServerConnection serverConnection;
    private final DBCollection collection;
    private final Table table;

    public CollectionBrowserComponent(ServerConnection serverConnection, DBCollection collection) {
        this.serverConnection = serverConnection;
        this.collection = collection;

        table = createTable();

        addComponent(createQueryController(collection, table));
        addComponent(table);
        setExpandRatio(table, 1);
        setSizeFull();
    }

    private Table createTable() {
        Table table = new Table();
        table.setSizeFull();
        table.setNullSelectionAllowed(false);
        table.setSelectable(true);
        table.setColumnHeaderMode(Table.ColumnHeaderMode.HIDDEN);
        return table;
    }

    private Component createQueryController(DBCollection collection, Table table) {
        return new QueryControllerComponent(collection, table);
    }
}
